package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entites.JsonResult;
import com.atguigu.springcloud.entites.Payment;
import com.atguigu.springcloud.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PaymentController
 * @Author VCR
 * @Date 2021/12/20 21:09
 * @Version 1.0
 */
@RestController
@RequestMapping("payment")
public class PaymentController {

    @Autowired
    private IPaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("create")
    public JsonResult create(@RequestBody Payment payment) {
        int insert = paymentService.insert(payment);
        System.out.println(insert);
        System.out.println("999999");
        return new JsonResult(200, "insert success,serverPort:" + serverPort, insert);
    }

    @GetMapping("/get/{id}")
    public JsonResult queryPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.queryPaymentById(id);
        System.out.println("324242");
        if (payment != null) {
            return new JsonResult(200, "insert success,serverPort:" + serverPort, payment);
        } else {
            return JsonResult.defaultError();
        }

    }
}
